package com.microstream.lift.guestbook;
import java.io.IOException;
import java.util.Date;
import javax.jdo.PersistenceManager;
import javax.servlet.http.*;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import com.microstream.lift.guestbook.Greeting;
import com.microstream.lift.guestbook.PMF;
import com.microstream.dao.MsUser;
import com.microstream.global.*;

public class SignGuestbookServlet extends HttpServlet {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//private static final Logger log = Logger.getLogger(SignGuestbookServlet.class.getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
        //UserService userService = UserServiceFactory.getUserService();
        //User user = userService.getCurrentUser();        
    	HttpSession session = req.getSession(true);
    	
    	String userName = session.getAttribute( GlobalConstant.SESSION_USER_LOGIN_NAME ).toString();   
    	
        String title = req.getParameter("title");
        String content = req.getParameter("content");        
        Date date = new Date();
        Greeting greeting = new Greeting(userName, title,content, date);               

        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(greeting);
        } finally {
            pm.close();
        }
                   	    
        resp.sendRedirect("guestbook.jsp");
    }
}
